<?php

namespace App\Http\Controllers\Main;

use App\Helpers\ResponseData;
use App\Helpers\StatisticsTrait;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class LocalTestController extends Controller
{
    use ResponseData,StatisticsTrait;
    public function index(){
        $data =  '当前磁盘的剩余空间：' . $this->get_disk_total(disk_free_space('.')) ;
       // list($start,$end) = $this->getthemonth('2022-11-22 00:00:00');
        return $this->success($data);
    }
    public //PHP获取磁盘大小
    function get_disk_total(int $total) : string
    {
        $config = [
            '3' => 'GB',
            '2' => 'MB',
            '1' => 'KB'
        ];
        foreach($config as $key => $value){
            if($total > pow(1024, $key)){
                return round($total / pow(1024,$key)).$value;
            }
            return $total . 'B';
        }
    }

}
